package infra

import (
	"github.com/flosch/pongo2/v6"
)

func SqlFromTemplate(tpl string, conds map[string]any) (string, error) {
	template, err := pongo2.FromString(tpl)
	if err != nil {
		return "", err
	}
	ctxData := pongo2.Context{}

	for k, v := range conds {
		ctxData[k] = v
	}
	sql, err := template.Execute(ctxData)
	if err != nil {
		return "", err
	}
	return sql, nil
}
